class ProfileController < ApplicationController
  def index
    list
    render :action => 'list'
  end

  def view
  end

  # GETs should be safe (see http://www.w3.org/2001/tag/doc/whenToUseGet.html)
  verify :method => :post, :only => [ :destroy, :create, :update ],
         :redirect_to => { :action => :list }

  def list
    @profile_pages, @profiles = paginate :profiles, :per_page => 10
  end

  def show
    @profile = Profile.find(params[:id])
    @user = User.find(@profile.user_id)
  end

  # profiles are created whenever a user is created
  #def new
  #  @profile = Profile.new
  #end

  def create
    @profile = Profile.new(params[:profile])
    if @profile.save
      flash[:notice] = 'Profile was successfully created.'
      redirect_to :action => 'list'
    else
      render :action => 'new'
    end
  end

  def edit
    @profile = Profile.find(params[:id])
    @user = User.find(@profile.user_id)
  end

  def update
    @profile = Profile.find(params[:id])
    if @profile.update_attributes(params[:profile])
      flash[:notice] = 'Profile was successfully updated.'
      redirect_to :action => 'show', :id => @profile
    else
      render :action => 'edit'
    end
  end

end
